<script setup>
import {
    Management,
    UserFilled,
    User,
    Crop,
    EditPen,
    SwitchButton,
    CaretBottom,
    Tickets
} from "@element-plus/icons-vue";
import avatar from "@/src-manager/assets/default.png";
import router from "@/src-manager/router/index.js";

import { useemployeeInfoStore } from "@/src-manager/stores/employeeInfo.js";
import { ref ,watch} from "vue";

const empInfoStore = useemployeeInfoStore();

const emp_pic = ref(empInfoStore.info.empPic);
const emp_name = ref(empInfoStore.info.employeeName);

watch(empInfoStore.info, (newValue) => {
    if (newValue) {

        emp_pic.value = newValue.empPic;
    }
});


// 条目被点击后的函数
import { ElMessage, ElMessageBox } from "element-plus";
import { useTokenStore } from "../stores/token.js";
const tokenStore = useTokenStore();


const handleCommand = (command) => {
    if (command === "logout") {
        ElMessageBox.confirm("你确认要退出吗?", "温馨提示", {
            confirmButtonText: "OK",
            cancelButtonText: "Cancel",
            type: "warning",
        })
            .then(async () => {
                // 退出登录
                //1. 去除pinia中保存token和个人信息
                tokenStore.removeToken();
                userInfoStore.removeInfo();

                // 跳转到登录界面
                router.push("/manager/emplogin");

                ElMessage({
                    type: "success",
                    message: "logout completed",
                });
            })
            .catch(() => {
                ElMessage({
                    type: "info",
                    message: "logout canceled",
                });
            });
    } else {
        //路由

        router.push("/manager/employee/" + command);
    }
};



</script>

<template>
    <el-container class="layout-container">
        <!-- 左侧菜单 -->
        <el-aside width="200px">
            <div class="el-aside__logo"></div>
            <el-menu active-text-color="#0d7ff1" background-color="#fff" text-color="#120101" router>






                <el-menu-item index="/manager/operation/ticket">
                    <el-icon>
                        <Tickets />
                    </el-icon>
                    <span>机票管理</span>
                </el-menu-item>


                <el-menu-item index="/manager/operation/order">
                    <el-icon>
                        <EditPen />
                    </el-icon>
                    <span>订单查看</span>
                </el-menu-item>

                <el-menu-item index="/manager/employee/manageruser">
                    <el-icon>
                        <Management />
                    </el-icon>
                    <span>用户管理</span>
                </el-menu-item>

                <el-menu-item index="/manager/operation/datastatistics">
                    <el-icon>
                        <Crop />
                    </el-icon>
                    <span>数据统计</span>
                </el-menu-item>


                <el-sub-menu>
                    <template #title>
                        <el-icon>
                            <UserFilled />
                        </el-icon>
                        <span>管理员中心</span>
                    </template>
                    <el-menu-item index="/manager/employee/info">
                        <el-icon>
                            <User />
                        </el-icon>
                        <span>基本资料</span>
                    </el-menu-item>
                    <el-menu-item index="/manager/employee/avatar">
                        <el-icon>
                            <Crop />
                        </el-icon>
                        <span>更换头像</span>
                    </el-menu-item>
                    <el-menu-item index="/manager/employee/resetpassword">
                        <el-icon>
                            <EditPen />
                        </el-icon>
                        <span>重置密码</span>
                    </el-menu-item>



                </el-sub-menu>
            </el-menu>
        </el-aside>
        <!-- 右侧主区域 -->
        <el-container>
            <!-- 头部区域 -->
            <el-header>
                <div>管理员：{{emp_name}}<strong></strong></div>
                <el-dropdown placement="bottom-end" @command="handleCommand">

                    <span class="el-dropdown__box">


                        <el-avatar v-if="emp_pic" :src="emp_pic" />
                        <el-avatar v-else :src="avatar" />


                        <el-icon>
                            <CaretBottom />
                        </el-icon>
                    </span>

                    <template #dropdown>
                        <el-dropdown-menu>
                            <el-dropdown-item command="info" :icon="User">基本资料</el-dropdown-item>
                            <el-dropdown-item command="avatar" :icon="Crop">更换头像</el-dropdown-item>
                            <el-dropdown-item command="resetpassword" :icon="EditPen">重置密码</el-dropdown-item>
                            <el-dropdown-item command="logout" :icon="SwitchButton">退出登录</el-dropdown-item>
                        </el-dropdown-menu>
                    </template>
                </el-dropdown>
            </el-header>
            <!-- 中间区域 -->
            <el-main>
                <div style="width: 1290px; height: 570px;border: 1px solid red;">
                    <router-view></router-view>
                </div>
            </el-main>
            <!-- 底部区域 -->
            <el-footer>平安机票管理系统 ©2023 Created by Mr.j</el-footer>
        </el-container>
    </el-container>
</template>

<style lang="scss" scoped>
.layout-container {
    height: 100vh;

    .el-aside {
        background-color: #0b6bf1;

        &__logo {
            height: 120px;
            background: url('@/src-client/assets/logo.png') no-repeat center / 200px auto;
        }

        .el-menu {
            border-right: none;
        }
    }

    .el-header {
        background-color: #fff;
        display: flex;
        align-items: center;
        justify-content: space-between;

        .el-dropdown__box {
            display: flex;
            align-items: center;

            .el-icon {
                color: #0d7ff1;
                margin-left: 10px;
            }

            &:active,
            &:focus {
                outline: none;
            }
        }
    }

    .el-footer {
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 14px;
        color: #120101;
    }
}
</style>